<?php

namespace app\wechat\controller;

use app\wechat\controller\Base;
use EasyWeChat\Kernel\Messages\Message;

class Index extends Base
{
    public function index()
    {
        $this->app->server->push(fn ($payload) => var_export($payload, true));
        $this->app->server->push(\Wechat\MessageHandlers\TextHandler::class,  Message::TEXT);
        $this->app->server->push(\Wechat\MessageHandlers\EventHandler::class,  Message::EVENT);
        $response = $this->app->server->serve();
        return $response->send();
    }

    public function menu()
    {
        $buttons = [
            [
                "type" => 'view',
                "name" => '联系客服',
                'url'  => url('/', null, null, true)
            ]
        ];
        $this->app->menu->delete();
        return json_encode($this->app->menu->create($buttons));
    }
}
